package com.tanger.im.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.tanger.im.entity.ImUserContacts;
import com.tanger.im.entity.IMUserContactsVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Description TODO
 * @Author Hchenbin
 * @Date 2023-12-25 15:29
 * @Version 1.0
 */
public interface IMUserContactsRepository extends BaseMapper<ImUserContacts> {

    @Select(
            "select " +
                    "uc.id, u.id as userId, " +
                    "ifnull(uc.name, u.nick_name) as name, " +
                    "u.mobile, u.avatar, u.sex, u.remark " +
            "from im_user_contacts uc " +
            "left join im_user u ON uc.crony_id = u.id " +
            "where uc.is_black = 0 " +
                   "and is_del = 0 " +
                   "and uc.user_id = #{userId,jdbcType=BIGINT} "
    )
    List<IMUserContactsVO> findAll(@Param("userId") Long userId);

    @Select(
            "select " +
                    "uc.id, u.id as userId, " +
                    "ifnull(uc.name, u.nick_name) as name, " +
                    "u.mobile, u.avatar, u.sex, u.remark " +
                    "from im_user_contacts uc " +
                    "left join im_user u ON uc.crony_id = u.id " +
                    "where uc.id = #{id,jdbcType=BIGINT} "
    )
    IMUserContactsVO findOne(@Param("id") Long id);
}
